# w write  写入   
with open('9-4.txt','w',encoding='utf-8') as f:
    f.write('我是写入的内容\n')



#将原本内容的第二行修改为666
f = open('9-4-1.txt','r',encoding='utf-8')
str1 = f.read()
str2 = str1.replace('222','666')
f.close()

fw = open('9-4-1.txt','w',encoding='utf-8')
fw.write(str2)
#flush 确认写入
fw.flush()

fr = open('9-4-1.txt','r',encoding='utf-8')
print(fr.read())
fr.close()